package com.liuc.practice.login.controller;

import com.liuc.practice.login.service.LoginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.net.http.HttpRequest;

/**
 * @Author Liu Chang
 * @Date 2021/9/19 3:02 下午
 */
@Controller
@RequestMapping("/user")
public class LoginController {

    @Autowired
    private LoginService service;

    @RequestMapping("/toLogin")
    public String toLogin() {
        return "login";
    }
    @RequestMapping("/success")
    public String success() {
        return "success";
    }

    @RequestMapping("/login")
    public String login(String username, String password, HttpSession session) throws Exception {
        if (service.checkUser(username, password)) {
            session.setAttribute("username", username);
            return "success";
        } else {
            return "login";
        }
    }
}
